package com.awenhui.demo.filter;

import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * OncePerRequestFilter 它能够确保在一次请求中只通过一次filter
 * @author yuxf
 * @version 1.0
 * @date 2020/5/9 11:15
 */
@WebFilter(urlPatterns = "/demo/*")
public class MyFilter1 extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {

        String requestURI = request.getRequestURI();
        System.out.println("--------------------->过滤器"+this.getClass().getName()+"开始执行：请求地址"+requestURI);

        filterChain.doFilter(request,response);
     //   System.out.println(this.getClass().getName()+"--------------------->执行结束");
    }
}
